package me.zhengjie.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.ServletRequestHandledEvent;

/**
 * <b>请输入名称</b>
 * <pre>
 * 描述<br/>
 * 作用：；<br/>
 * 限制：；<br/>
 * </pre>
 *
 * @author 胡安稳
 * @date 2024/12/4 15:59
 */
@Component
@Slf4j
public class TakeTimeCountListener implements ApplicationListener<ServletRequestHandledEvent> {

    @Override
    public void onApplicationEvent(ServletRequestHandledEvent event) {
        Throwable failureCause = event.getFailureCause();

//        log.info("请求客户端地址：{}, 请求URL: {}, 请求Method: {}, 请求耗时: {}ms",
//                event.getClientAddress(),
//                event.getRequestUrl(),
//                event.getMethod(),
//                event.getProcessingTimeMillis());
        log.info(event.getDescription());
        if (failureCause != null) {
            log.error("错误原因: {}", failureCause.getMessage());
        }

    }
}
